package com.duowei.diandan.db.dao;

import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;

import com.duowei.diandan.db.entry.Mzszjbxx;

import java.util.List;

@Dao
public interface MzszjbxxDao {

    @Query("SELECT * FROM mzszjbxx")
    List<Mzszjbxx> findAll();

    /**
     * @param xmbh 单品编号
     * @param rq   当前日期 yyyy-MM-dd
     * @param sj   当前时间 HH:mm
     */
    @Query("SELECT * FROM mzszjbxx " +
            "WHERE xmbh = :xmbh " +
            "AND :rq BETWEEN ksrq AND jsrq " +
            "AND :sj BETWEEN kssj AND jssj " +
            "LIMIT 1")
    Mzszjbxx findOneByXmbh(String xmbh, String rq, String sj);

    @Query("SELECT * FROM mzszjbxx WHERE xmbh = :xmbh")
    LiveData<List<Mzszjbxx>> findByXmbh(String xmbh);

    @Insert
    void insert(List<Mzszjbxx> list);

    @Query("DELETE FROM mzszjbxx")
    void deleteAll();
}
